<?php

namespace Togetwzb\Yii2\Aliyun\Oss\filters;

use OSS\OssClient;
use yii\base\BaseObject;
use yii\base\InvalidConfigException;

/**
 * 过滤参数对象
 * @see FileFilter::$filterParamsCallback
 */
class FilterParams extends BaseObject
{
    /**
     * @var string
     */
    public $fromBucket;

    /**
     * @var string
     */
    public $toBucket;

    /**
     * @var string
     */
    public $fromObject;

    /**
     * @var string
     */
    public $toObject;

    /**
     * @var array
     */
    public $deleteOption;

    /**
     * @var array|callable
     */
    public $option;

    /**
     * @var OssClient
     */
    public $ossClient;

    public function init()
    {
        parent::init();

        if (!$this->ossClient instanceof OssClient) {
            throw new InvalidConfigException('ossClient not instanceof OssClient.');
        }
        if (is_null($this->fromBucket)) {
            throw new InvalidConfigException('fromBucket must be set.');
        }

        if (is_null($this->toBucket)) {
            $this->toBucket = $this->fromBucket;
        }

        if (is_null($this->fromObject)) {
            throw new InvalidConfigException('fromObject must be set.');
        }

        if (is_null($this->toObject)) {
            $this->toObject = $this->fromObject;
        }
    }
}